/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-07 09:51:01
 * @LastEditors: 颜礼田 2564217790@qq.com
 * @LastEditTime: 2024-09-07 10:36:26
 * @FilePath: /webServer/src/middleware/response.middleware.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Middleware, IMiddleware } from '@midwayjs/core';
import { NextFunction, Context } from '@midwayjs/koa';
import { useSuccess } from '../utils/resHelper';

@Middleware()
export class ResponseMiddleware implements IMiddleware<Context, NextFunction> {
  resolve() {
    return async (_ctx: Context, next: NextFunction) => {
      const result = await next();
      // 返回给上一个中间件的结果
      return useSuccess(result);
    };
  }

  static getName(): string {
    return 'response';
  }
}
